<script setup>
import {ref,watch} from 'vue';
let money = ref(2000);

let buy = (m)=>{
  money.value -=m;
}

watch(money,(newV,oldV)=>{
  if(newV < 0){
    alert('余额不足！');
    money.value=oldV;
  }else if(newV < 200){
    document.getElementById('money').style.color ='red';
    alert('钱快花光了！留点吃饭吧！！！')
  }
})
</script>

<template>
  <div>
    <p>零花钱：<span id="money">{{ money }}</span></p>
    <p>
      <button @click="buy(198)">购物198</button>
      <button @click="buy(298)">购物298</button>
      <button @click="buy(598)">购物598</button>
    </p>
  </div>
</template>

<style scoped>
.logo {
  height: 6em;
  padding: 1.5em;
  will-change: filter;
  transition: filter 300ms;
}
.logo:hover {
  filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
  filter: drop-shadow(0 0 2em #42b883aa);
}
</style>
